<template>
  <van-nav-bar title="定位测试" />
  <div>

    <van-cell-group>
    </van-cell-group>
    <van-button type="primary" style=" margin-top: 20px;" @click="doCall">获取当前位置</van-button>
  </div>
  <van-cell-group inset>
    <van-field  v-model="data.locationStr"  label-align="top" rows="10" autosize label="位置信息" type="textarea" />
  </van-cell-group>
</template>

<script setup lang='ts' name=''>
import { reactive, ref } from "vue";


// Your script here

let data = reactive({
  locationStr: "",
});


const doCall = () => {


  (window as any).whJSBridge.activeLocation().then(
    function (res: any) {
      console.log("获取定位成功", res);

      data.locationStr = JSON.stringify(res)

    }).catch(function (err: any) {
      console.log(JSON.stringify(err));

      if ('object' == typeof err) {
        alert('定位出错：' + JSON.stringify(err))
      } else {
        alert('定位出错：' + err)
      }
    });


}



</script>

<style scoped>
/* Your styles here */
</style>